#!/bin/bash

# ################# cfg ##################
# yaml dev 配置:
# dev_dependencies:
#   source_gen: ^1.0.0
#   build_runner: ^1.12.2
#   xanno: ^0.0.5+1
#
# 项目根目录执行命令:
# flutter pub get && flutter packages pub run build_runner build && flutter pub get
#
# 授权 chmod +x build.sh
# 之后只需执行 ./build.sh
# ################# cfg ##################

if [[ $1 == '-h' || $1 == '-help' ]]; then
  printf "\t %s \n" "已实现下列功能："
  printf "\t\t %s \n" "1:@GApi注解"
  printf "\t\t %s \n" "2:@GAssets注解"
  printf "\t\t %s \n" "3:@GColor注解"
  printf "\t\t %s \n" "4:@GEntity注解"
  printf "\t\t %s \n" "5:@GFormatter注解"
  printf "\t\t %s \n" "6:@GHttp注解"
  printf "\t\t %s \n" "7:@GIconFont注解"
  printf "\t\t %s \n" "8:@GProject注解"
  printf "\t\t %s \n" "9:@GRoute注解"
  printf "\t\t %s \n" "10:@GSize注解"
else
#  发布pub.dev,关闭代理PUB_HOSTED_URL、FLUTTER_STORAGE_BASE_URL,执行flutter pub get
#  flutter packages pub publish --dry-run
#  flutter packages pub publish
#  sudo flutter packages pub publish -v
  echo "生成和优化代码，请等待..."
  flutter pub get
  pub global activate dart_style >/dev/null 2>&1
  flutter packages pub run build_runner build --delete-conflicting-outputs
  flutter pub get
  info="./ios/Runner/Info.plist"
  [ ! -f "$info" ] && exit
#  echo "正在修改plist..."
#  /usr/libexec/PlistBuddy -c 'add io.flutter.embedded_views_preview bool YES' $info
#  /usr/libexec/PlistBuddy -c "add NSAppTransportSecurity:NSAllowsArbitraryLoadsInWebContent bool YES" $info
#  /usr/libexec/PlistBuddy -c "add NSAppTransportSecurity:NSAllowsArbitraryLoads bool YES" $info
#  /usr/libexec/PlistBuddy -c "add NSMicrophoneUsageDescription string 需要您的同意,App才能访问麦克风进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSPhotoLibraryUsageDescription string 需要您的同意,App才能访问相册进行管理" $info
#  /usr/libexec/PlistBuddy -c "add NSCameraUsageDescription string 需要您的同意,App才能访问相机进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSBluetoothAlwaysUsageDescription string 需要您的同意,App才能访问蓝牙进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSBluetoothPeripheralUsageDescription string 需要您的同意,App才能访问蓝牙进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSFaceIDUsageDescription string 需要您的同意,App才能访问面容ID进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSLocationAlwaysUsageDescription string 需要您的同意,App才能访问位置信息进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSLocationAlwaysAndWhenInUseUsageDescription string 需要您的同意,App才能访问位置信息进行检测" $info
#  /usr/libexec/PlistBuddy -c "add NSLocationWhenInUseUsageDescription string 需要您的同意,App才能访问位置信息" $info
#  echo "修改plist完成"
fi
